package com.activities;

import com.fragments.GroupContactFragment;
import com.fragments.MessageFragment;
import com.fragments.MyContactFragment;
import com.senditcertified.mail.R;

import android.support.v4.app.Fragment;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class ViewSecurityPackageActivity extends BaseFragmentActivity implements
		OnClickListener {
	private LinearLayout mLnMessage;
	private LinearLayout mLnReci;
	private LinearLayout mLnAtta;

	private int tabTextColorNormal;
	private int tabTextColorFocus;

	@Override
	public void onClick(View v) {
		if (v == mLnMessage) {
			mLnMessage.setBackgroundResource(R.drawable.btn_contact_tab_focus);
			((ImageView) mLnMessage.getChildAt(0))
					.setImageResource(R.drawable.ic_contact_focus);
			((TextView) mLnMessage.getChildAt(1))
					.setTextColor(tabTextColorFocus);

			mLnReci.setBackgroundResource(R.drawable.button_tab);
			((ImageView) mLnReci.getChildAt(0))
					.setImageResource(R.drawable.ic_group_contact_normal);
			((TextView) mLnReci.getChildAt(1)).setTextColor(tabTextColorNormal);
			mLnAtta.setBackgroundResource(R.drawable.button_tab);
			((ImageView) mLnAtta.getChildAt(0))
					.setImageResource(R.drawable.ic_group_contact_normal);
			((TextView) mLnAtta.getChildAt(1)).setTextColor(tabTextColorNormal);
			showMessageFragment();
		}
	}

	@Override
	protected void initViews() {
		mLnMessage = (LinearLayout) findViewById(R.id.ln_message);
		mLnReci = (LinearLayout) findViewById(R.id.ln_reci);
		mLnAtta = (LinearLayout) findViewById(R.id.ln_attach);
	}

	@Override
	protected void onResume() {
		Fragment currentFragment = getSupportFragmentManager()
				.findFragmentById(R.id.frame_main);
		if (currentFragment instanceof GroupContactFragment) {
			GroupContactFragment fragment = (GroupContactFragment) currentFragment;
			fragment.getData();

		} else if (currentFragment instanceof MyContactFragment) {
			MyContactFragment fragment = (MyContactFragment) currentFragment;
			fragment.getData();

		} else {
			// showContactFragment();
		}// for reload Data
		super.onResume();
	}

	@Override
	protected int initLayout() {
		return R.layout.activity_securepakage;
	}

	@Override
	protected void initComponents() {
		// TODO Auto-generated method stub

	}

	@Override
	protected void addListener() {
		mLnAtta.setOnClickListener(this);
		mLnMessage.setOnClickListener(this);
		mLnReci.setOnClickListener(this);
	}

	public void showMessageFragment() {
		Fragment currentFragment = getSupportFragmentManager()
				.findFragmentById(R.id.frame_main);
		if (!(currentFragment instanceof MessageFragment)) {
			MessageFragment fragment = new MessageFragment();
			if (fragment != null) {
				setNewPage(fragment);
			}
		}
	}
}
